var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    names: '',
    score: 420,
    // user:[
    //   { img: '../../images/u213.png', text: '我的旅行口味', read: '查看排名 >', state: '0',},
    //   { img: '../../images/u213.png', text: '我的旅行口味', read: '查看排名 >', state: '0',},
    //   { img: '../../images/u213.png', text: '我的旅行口味', read: '查看排名 >', state: '0',},
    //   { img: '../../images/u213.png', text: '我的旅行口味', istrue: '1', state:'1',},
    //   { img: '../../images/u213.png', text: '我的旅行口味', istrue: '1', state:'1',},
    //   { img: '../../images/u213.png', text: '我的旅行口味', istrue: '1', state:'1',},
    // ]
  },
  //  跳转到排名页面
  reads: function (e) {
    wx.navigateTo({
      url: '../rank/index?cid=' + e.currentTarget.dataset.cid,
    })
  },
  // 跳转到积分
  click: function (e) {
    console.log(333);
    wx.reLaunch({
      url: '../details/index',
    })
    console.log(555);
  },
  //  跳转到修改页面
  modify: function (e) {
    wx.navigateTo({
      url: '../setquest/index?id=' + e.currentTarget.dataset.tid + '&cid=' + e.currentTarget.dataset.cid,
    })
  },
  //  跳转到分享页面
  share: function (e) {
    wx.navigateTo({
      url: '../share/index?code_url=https://hd.huwaishequ.com/djred/public/wxcode/wx' + e.currentTarget.dataset.cid + '.png&cid=' + e.currentTarget.dataset.cid,
    })
  },
  //  跳转到设置页面
  setting: function (e) {
    wx.navigateTo({
      url: '../setquest/index?id=' + e.currentTarget.dataset.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (wx.getStorageSync('openid') == '') {
      console.log('现在去获取openid');
      app.load(that.onLoad);
    } else {
      that.log_load();
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    // that.log_load();        
    if (wx.getStorageSync('openid') == '') {
      app.load(that.log_load);
    } else {
      that.log_load();
    }
  },

  // 登录后加载
  log_load: function (e, c) {
    wx.showLoading({ title: 'loading', mask: true })
    var that = this;
    var openid = wx.getStorageSync('openid');
    console.log('openid:' + openid);
    if (openid == '' || openid == null) {
      openid = c;
    }
    wx.request({
      url: app.url + 'api/shou',
      data: {
        openid: openid,
        token: wx.getStorageSync('token_md5'),
      },
      header: { 'content-type': 'application/json' },
      success: function (res) {
        console.log(res.data);
        var data = res.data;
        that.setData({
          user_img: wx.getStorageSync('avatarurl'),
          user_nickname: wx.getStorageSync('nickname'),
          user: data.tdata,
          score: data.score,
        })
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})